<template>
	<view class="content">
		<view v-html="content"></view>
		<view v-if="commpany!=''" v-html="commpany"></view>
		<view v-if="content==''">
			未设置{{name}}~~~
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				content:'',
				commpany: '',
				name: ''
			}
		},
		onLoad(query){
			if(query.type == 'user'){
				this.getUserRight();
				this.name = '服务协议'
			}else{
				this.getIntegralRule();
				this.name = '积分规则'
			}
		},
		methods:{
			async getIntegralRule(){
				//获取积分规则
				let res=await this.$api.getIntegralRule()
				if(res.data.level=='success'){
					let str = res.data.data.content;
					str = str.replace(/<img[^>]*>/gi, function (match, capture) {
						return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, '')
					})
					str = str.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ');
					this.content = str;
				}
			},
			//获取服务协议
			async getUserRight(){
				let res=await this.$api.getServiceAgreement({user_token: uni.getStorageSync('userToken')});
				if(res.data.level == 'success'){
					let str = res.data.data.content;
					str = str.replace(/<img[^>]*>/gi, function (match, capture) {
						return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, '')
					})
					str = str.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ');
					this.content = str;
				}
			},
			htmeText(text){
				text = text.replace(/<img[^>]*>/gi, function (match, capture) {
					return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, '')
				});
				text = text.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ');
				return text;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 30rpx;
	}
</style>